require File.join(File.dirname(__FILE__), '../clock')

class TestClock < Test::Unit::TestCase
   
   def setup
      @clock1 = Clock.new(5)
      @clock2 = Clock.new(3, [1,1,0])
   end
   
   def teardown
      # Nothing really
   end
   
   def test_simple
      assert_equal(5, @clock1.vector.length)
      assert_equal([0,0,0,0,0], @clock1.vector)
      assert_equal(Clock.new(5), @clock1)
      assert_equal("[0, 0, 0, 0, 0]", @clock1.to_s)
      assert_equal(@clock1, Clock.from_s(@clock1.to_s))
      
      @clock1.inc(0)
      assert_equal([1,0,0,0,0], @clock1.vector)
      @clock1.inc(1)
      assert_equal([1,1,0,0,0], @clock1.vector)
      @clock1.inc(2)
      assert_equal([1,1,1,0,0], @clock1.vector)
      @clock1.inc(3)
      assert_equal([1,1,1,1,0], @clock1.vector)
      @clock1.inc(4)
      assert_equal([1,1,1,1,1], @clock1.vector)
      
      assert_equal(3, @clock2.vector.length)
      assert_equal([1,1,0], @clock2.vector)
      assert_not_equal(Clock.new(3), @clock1)
      assert_equal("[1, 1, 0]", @clock2.to_s)
      assert_equal(@clock2, Clock.from_s(@clock2.to_s))
      
   end
   
   def test_typecheck
      assert_raise( RuntimeError ) { Clock.new("2") }
      assert_raise( RuntimeError ) { Clock.new(2, "") }
      assert_raise( RuntimeError ) { Clock.new(2, [0,0,0]) }
   end
   
end 

